package algorithm.stack;

import org.omg.PortableInterceptor.INACTIVE;

import java.util.Stack;

/**
 * 用一个栈对另一个栈排序
 * Created by zhy on 2017/9/3.
 */
public class Main4 {
    public static Stack<Integer> sortStackByStack(Stack<Integer> stack){
        Stack<Integer> help = new Stack<Integer>();
        while(!stack.isEmpty()){
            int cur = stack.pop();
            while(!help.isEmpty() && help.peek()<cur){
                stack.push(help.pop());
            }
            help.push(cur);
        }
        return help;
    }

    public static void main(String[] args) {
        Stack<Integer> stack = new Stack<Integer>();
        stack.add(1);
        stack.add(2);
        stack.add(3);
        stack.add(4);
        System.out.println(sortStackByStack(stack).toString());
    }
}
